package top.onedream.buildsmallsoftware.cfg.Interceptor

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor
import org.springframework.web.servlet.ModelAndView
import top.onedream.buildsmallsoftware.util.TokenHolder
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@Component
class TokenInterceptor : HandlerInterceptor {

    private val logger: Logger = LoggerFactory.getLogger(JwtInterceptor::class.java)

    override fun postHandle(
        request: HttpServletRequest,
        response: HttpServletResponse,
        handler: Any,
        modelAndView: ModelAndView?
    ) {
        try {
            TokenHolder.user.let { it -> logger.info("用户:" + it.id + "结束访问") }
            TokenHolder.removeToken()
        }catch (e:Exception){
            logger.warn("无人访问异常")
        }
        super.postHandle(request, response, handler, modelAndView)
    }
}